import {
	createStore
} from 'vuex'


const state = { //数据存放的位置
	person: {
		name: 'defaultName',
		sex: 'defaultSex',
		age: 'defaultAge'
	}
}
const getters = {
	getPerson(state) {
		return state.person
	}
}

const actions = { //通过actions触发mutations的方法
	disPatchPerson({ commit }){
		setTimeout(()=>{
			commit('setPerson', {
				name: 'yangxian',
				sex: 'men',
				age: 26
			})
		})
	}
}

const mutations = { //在mutations写方法更改state中的值
	setPerson(state,data) {
		state.person = data
	}
}

const store = createStore({
	state,
	getters,
	actions,
	mutations
})
//导出store对象
export default store;